/*******************************************************************************
 * Copyright (c) 2012 AwOiSoAk.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Public License v3.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/gpl.html
 * 
 * Contributors:
 *     $AwOiSoAk - initial API and implementation
 ******************************************************************************/
package com.awoisoak.dundeeguide;




import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class Main extends Activity implements OnItemClickListener{
 
	
	//Variable to keep the id of the row pressed on the ListView
	long id = 666;
	
	//Variables that will be sent by put.extra() 
	Intent i;
	String coord= null;
	String website = null;
	int explanation=0;
	String place =null;
	int iconPlace=0;


	
	
    private ListView listViewDundee;
	private String[] stringDundee;
	private ArrayAdapter<String> aa;		
    
    
    @Override
	public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        listViewDundee = (ListView)findViewById(R.id.listViewDundee);
        stringDundee = new String[]{"Attractions","Restaurants","Nightlife","Map"};
        aa = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,stringDundee);
        listViewDundee.setAdapter(aa);
        listViewDundee.setOnItemClickListener(this);
        registerForContextMenu(listViewDundee);
        
        
        
    }


	@Override
	public void onItemClick(AdapterView<?> av, View v, int position, long arg3) {
		String item = stringDundee[position].toString();
		if (item =="Attractions"){
			i = new Intent(Main.this,Attractions.class);
			startActivity(i);
		}
		if (item == "Restaurants"){
			i = new Intent(Main.this,Restaurants.class);
			startActivity(i);
		}
		if (item == "Nightlife"){
			i = new Intent(Main.this,Nightlifes.class);
			startActivity(i);
		}
		if (item == "Map"){
			coord="0,0";
			i = new Intent(Main.this,Map.class);
			i.putExtra("tag_coordinate", coord);
			startActivity(i);

		}
			
		
	}


	@Override
	public void onCreateContextMenu(ContextMenu menu, View v,
			ContextMenuInfo menuInfo) {
		
		
		//We will get the id of the row that was pressed (Attraction=0,Restaurants=1...)
		AdapterView.AdapterContextMenuInfo info;
		info = (AdapterView.AdapterContextMenuInfo) menuInfo;
		id = listViewDundee.getAdapter().getItemId(info.position);		

		//Now me create the inflater and we'll inflate the specific menu layout
		MenuInflater inflater = getMenuInflater();
		if (id==0)
			inflater.inflate(R.menu.menu_attractions, menu);
		else if (id==1)
			inflater.inflate(R.menu.menu_restaurants, menu);
		else if (id==2)
			inflater.inflate(R.menu.menu_nightlifes, menu);
	
	}


	@Override
	public boolean onContextItemSelected(MenuItem item) {
		 super.onContextItemSelected(item);
				
		//If the Inflated menu was the Attraction... 
		if (id==0){
			openAttraction(item.getItemId());
			return true;
	
			}
		
		//If the Inflated menu was the Restaurant...
		else if (id==1){
			openRestaurant(item.getItemId());
			return true;
			}
		
		//If the Inflated menu was the Nightlife...	
		else if (id==2){
			openNightlife(item.getItemId());
			return true;
			}
		
		return false;
	}


	


	private void openAttraction(int itemId) {
		switch (itemId) {

		case (R.id.itemDundeeLaw): {
			coord = "56.469748,-2.989334";
			explanation = R.string.Dundee_Law;
			place = "Dundee Law";
			break;
		}
		case (R.id.itemMacManusGalleries): {
			coord = "56.462608,-2.971165";
			explanation = R.string.MacManus_Galleries;
			place = "McManus Galleries";
			break;
		}
		case (R.id.itemDiscoveryPoint): {
			coord="56.456848,-2.968358";
			explanation=R.string.Discovery_Point;;
			place = "Discovery Point";
			break;
		}
		case (R.id.itemHighStreet): {
			coord="56.460628,-2.970041";
			explanation=R.string.High_Street;
			place = "High Street";
			break;
		}
		case (R.id.itemBroughtyFerryCastle): {
			coord="56.462976,-2.870085";
			explanation=R.string.Broughty_Ferry;;
			place = "Broughty Ferry Castle";
			break;
		}
		
		}

		i = new Intent(Main.this, Attraction.class);
		i.putExtra("tag_coordinate", coord);
		i.putExtra("tag_place", place);
		i.putExtra("tag_explanation", explanation);
		startActivity(i);
	}
	
	
	
	private void openRestaurant(int itemId) {
		switch(itemId){
			case (R.id.itemTheByzantium):{	
				coord="56.459441,-2.980142";
				website="http://www.byzantiumrestaurant.com/Dundee/Home/";  
				explanation=R.string.The_Byzantium;
				place= "The Byzantium";
				iconPlace=R.drawable.ic_bread;
				break;
			}
			case (R.id.itemMarcoPolo):{	
				coord="56.46093,-2.9657";
				website="http://www.marcopolocuisine.co.uk/";
				explanation=R.string.Marco_Polo;
				place= "Marco Polo";
				iconPlace=R.drawable.ic_italy;
				break;
			}
			case (R.id.itemBeiderbeckes):{	
				coord="56.461082,-2.986007";
				website="http://www.beiderbeckesbistro.co.uk/";
				explanation=R.string.Beiderbeckes;
				place= "Beiderbeckes";
				iconPlace=R.drawable.ic_burger;

				break;
			}
			case (R.id.itemPancakePlace):{	
				coord="56.461162,-2.970873";
				website="http://thepancakeplace.net/";
				explanation=R.string.Pancake_Place;
				place= "Pancake Place";
				iconPlace=R.drawable.ic_cookies;
				break;
			}
			case (R.id.itemShehzadBaltiTandoori):{	
				coord="56.481442,-3.021983";
				website="http://www.ashokarestaurants.com/Ashoka%20Shak%20Dundee/";
				explanation=R.string.Shehzad_Balti_Tandoori;
				place= "Shehzad Balti Tandoori";
				iconPlace=R.drawable.ic_india;
				break;
			}
			case (R.id.itemRanchoPancho):{	
				coord="56.460992,-2.966922";
				website="http://www.ranchopancho.com/";
				explanation=R.string.Rancho_Pancho;
				place= "Rancho Pancho";
				iconPlace=R.drawable.ic_mexico;
				break;
			}

		}
		
		i = new Intent(Main.this,Restaurant.class);  
		i.putExtra("tag_coordinate", coord);
		i.putExtra("tag_icon", iconPlace);
		i.putExtra("tag_place", place);
		i.putExtra("tag_explanation", explanation);
		i.putExtra("tag_website", website);
		startActivity(i);
		
	}
	
	
	
	private void openNightlife(int itemId) {
		switch(itemId){
			case (R.id.itemFatSams):{	
				coord="56.460588,-2.977028";
				website="https://m.facebook.com/FatSams?v=feed";  
				explanation=R.string.Fat_Sams;
				place= "Fat Sams's";
				iconPlace=R.drawable.ic_fatsams;
				break;
			}
			case (R.id.itemUnion):{	
				coord="56.457879,-2.982356";
				website="https://m.facebook.com/DUSA.TheUnion?v=feed";
				explanation=R.string.Union;
				place= "DUSA The Union";
				iconPlace=R.drawable.ic_union;
				break;
			}
			case (R.id.itemReadingRooms):{	
				coord="56.464969,-2.961711";
				website="https://www.facebook.com/ReadingRooms";
				explanation=R.string.Reading_Rooms;
				place= "Reading Rooms";
				iconPlace=R.drawable.ic_readingrooms;

				break;
			}
			case (R.id.itemLiquidAndEnvy):{	
				coord="56.460514,-2.976719";
				website="https://www.facebook.com/DundeeLiquidEnvy/wall";
				explanation=R.string.Liquid_And_Envy;
				place= "Liquid and Envy";
				iconPlace=R.drawable.ic_liquid;
				break;
			}
			case (R.id.itemBeatGenerator):{	
				coord="56.460887,-2.976112";
				website="http://www.facebook.com/pages/Beat-Generator/185656164752";
				explanation=R.string.Beat_Generator;
				place= "Beat Generator Live!";
				iconPlace=R.drawable.ic_beatgenerator;
				break;
			}
			case (R.id.itemTheDoghouse):{	
				coord="56.460992,-2.966922";
				website="http://m.facebook.com/dundeedoghouse?v=feed";
				explanation=R.string.Doghouse;
				place= "The Doghouse";
				iconPlace=R.drawable.ic_beatgenerator;
				break;
			}

		}
		
		i = new Intent(Main.this,Nightlife.class);  
		i.putExtra("tag_coordinate", coord);
		i.putExtra("tag_icon", iconPlace);
		i.putExtra("tag_place", place);
		i.putExtra("tag_explanation", explanation);
		i.putExtra("tag_website", website);
		startActivity(i);
		
	}
	
}
